#include "Threadpool.h"
#include <stdlib.h>
#include <iostream>
#include <memory>

using std::cout;
using std::endl;
using std::unique_ptr;

class MyTask
{
public:
    void process()
    {
        //此处需要实现具体的逻辑
        ::srand(::clock());
        int number = ::rand()%100;
        cout << ">>BO_Threadpool.MyTask process number = " << number << endl;
    }
};

void test()
{
    /* MyTask task; */
    unique_ptr<MyTask> ptask(new MyTask());//堆对象
    Threadpool pool(4, 10);
    pool.start();

    int cnt = 20;
    while(cnt-- > 0)
    {
        //添加任务
        /* pool.addTask(std::bind(&MyTask::process, &task)); */
        pool.addTask(std::bind(&MyTask::process, ptask.get()));
        cout << "cnt = " << cnt << endl;
    }

    pool.stop();
}

int main(int argc, char **argv)
{
    test();
    return 0;
}

